<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The EventBuffer class</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="eventbase.stop.html">EventBase::stop</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="eventbuffer.add.html">EventBuffer::add</a></div>
 <div class="up"><a href="book.event.html">Event</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="class.eventbuffer" class="reference">
 <h1 class="title">The EventBuffer class</h1>
 
 <div class="partintro"><p class="verinfo">(PECL event &gt;= 1.5.0)</p>

  <div class="section" id="eventbuffer.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    <strong class="classname">EventBuffer</strong>
    represents Libevent&#039;s &quot;evbuffer&quot;, an utility functionality for buffered
    I/O.
   </p>
   <p class="para">
    Event buffers are meant to be generally useful for doing the &quot;buffer&quot; part
    of buffered network I/O.
   </p>
  </div>

  <div class="section" id="eventbuffer.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass">
     
    </div>

    <div class="classsynopsisinfo">
     <span class="ooclass">
      <strong class="classname">EventBuffer</strong>
     </span>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Constants */</div>
    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">integer</span>
      <var class="fieldsynopsis_varname"><a href="class.eventbuffer.html#eventbuffer.constants.eol-any"><var class="varname">EOL_ANY</var></a></var>
     <span class="initializer"> = 0</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">integer</span>
      <var class="fieldsynopsis_varname"><a href="class.eventbuffer.html#eventbuffer.constants.eol-crlf"><var class="varname">EOL_CRLF</var></a></var>
     <span class="initializer"> = 1</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">integer</span>
      <var class="fieldsynopsis_varname"><a href="class.eventbuffer.html#eventbuffer.constants.eol-crlf-strict"><var class="varname">EOL_CRLF_STRICT</var></a></var>
     <span class="initializer"> = 2</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">integer</span>
      <var class="fieldsynopsis_varname"><a href="class.eventbuffer.html#eventbuffer.constants.eol-lf"><var class="varname">EOL_LF</var></a></var>
     <span class="initializer"> = 3</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">integer</span>
      <var class="fieldsynopsis_varname"><a href="class.eventbuffer.html#eventbuffer.constants.ptr-set"><var class="varname">PTR_SET</var></a></var>
     <span class="initializer"> = 0</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">integer</span>
      <var class="fieldsynopsis_varname"><a href="class.eventbuffer.html#eventbuffer.constants.ptr-add"><var class="varname">PTR_ADD</var></a></var>
     <span class="initializer"> = 1</span>
    ;</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 属性 */</div>
    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="modifier">readonly</span>
     <span class="type">int</span>
      <var class="varname"><a href="class.eventbuffer.html#eventbuffer.props.length">$<var class="varname">length</var></a></var>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="modifier">readonly</span>
     <span class="type">int</span>
      <var class="varname"><a href="class.eventbuffer.html#eventbuffer.props.contiguous-space">$<var class="varname">contiguous_space</var></a></var>
    ;</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span>
   <span class="methodname"><a href="eventbuffer.add.html" class="methodname">add</a></span>
    ( <span class="methodparam">
    <span class="type">string</span>
     <code class="parameter">$data</code>
   </span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span>
   <span class="methodname"><a href="eventbuffer.addbuffer.html" class="methodname">addBuffer</a></span>
    ( <span class="methodparam">
    <span class="type"><a href="class.eventbuffer.html" class="type EventBuffer">EventBuffer</a></span>
     <code class="parameter">$buf</code>
   </span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">int</span>
   <span class="methodname"><a href="eventbuffer.appendfrom.html" class="methodname">appendFrom</a></span>
    ( <span class="methodparam">
    <span class="type"><a href="class.eventbuffer.html" class="type EventBuffer">EventBuffer</a></span>
     <code class="parameter">$buf</code>
   </span>
   , <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$len</code>
   </span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="methodname"><a href="eventbuffer.construct.html" class="methodname">__construct</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">int</span>
   <span class="methodname"><a href="eventbuffer.copyout.html" class="methodname">copyout</a></span>
    ( <span class="methodparam">
    <span class="type">string</span>
     <code class="parameter reference">&$data</code>
   </span>
   , <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$max_bytes</code>
   </span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">void</span>
   <span class="methodname"><a href="eventbuffer.drain.html" class="methodname">drain</a></span>
    ( <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$len</code>
   </span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">void</span>
   <span class="methodname"><a href="eventbuffer.enablelocking.html" class="methodname">enableLocking</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span>
   <span class="methodname"><a href="eventbuffer.expand.html" class="methodname">expand</a></span>
    ( <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$len</code>
   </span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span>
   <span class="methodname"><a href="eventbuffer.freeze.html" class="methodname">freeze</a></span>
    ( <span class="methodparam">
    <span class="type">bool</span>
     <code class="parameter">$at_front</code>
   </span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">void</span>
   <span class="methodname"><a href="eventbuffer.lock.html" class="methodname">lock</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span>
   <span class="methodname"><a href="eventbuffer.prepend.html" class="methodname">prepend</a></span>
    ( <span class="methodparam">
    <span class="type">string</span>
     <code class="parameter">$data</code>
   </span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span>
   <span class="methodname"><a href="eventbuffer.prependbuffer.html" class="methodname">prependBuffer</a></span>
    ( <span class="methodparam">
    <span class="type"><a href="class.eventbuffer.html" class="type EventBuffer">EventBuffer</a></span>
     <code class="parameter">$buf</code>
   </span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">void</span>
   <span class="methodname"><a href="eventbuffer.pullup.html" class="methodname">pullup</a></span>
    ( <span class="methodparam">
    <span class="type">string</span>
     <code class="parameter">$size</code>
   </span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">string</span>
   <span class="methodname"><a href="eventbuffer.read.html" class="methodname">read</a></span>
    ( <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$max_bytes</code>
   </span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">string</span>
   <span class="methodname"><a href="eventbuffer.read.html" class="methodname">read</a></span>
    ( <span class="methodparam">
    <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span>
     <code class="parameter">$fd</code>
   </span>
   , <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$howmuch</code>
   </span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">void</span>
   <span class="methodname"><a href="eventbuffer.readline.html" class="methodname">readLine</a></span>
    ( <span class="methodparam">
    <span class="type">string</span>
     <code class="parameter">$eol_style</code>
   </span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">mixed</span>
   <span class="methodname"><a href="eventbuffer.search.html" class="methodname">search</a></span>
    ( <span class="methodparam">
    <span class="type">string</span>
     <code class="parameter">$what</code>
   </span>
   [, <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$start</code>
    <span class="initializer"> = -1</span>
   </span>
   [, <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$end</code>
    <span class="initializer"> = -1</span>
   </span>
  ]] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">mixed</span>
   <span class="methodname"><a href="eventbuffer.searcheol.html" class="methodname">searchEol</a></span>
    ([ <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$start</code>
    <span class="initializer"> = -1</span>
   </span>
   [, <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$eol_style</code>
    <span class="initializer"> = 
     <strong><code>EventBuffer::EOL_ANY</code></strong>
    </span>
   </span>
  ]] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">string</span>
   <span class="methodname"><a href="eventbuffer.substr.html" class="methodname">substr</a></span>
    ( <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$start</code>
   </span>
   [, <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$length</code>
   </span>
  ] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span>
   <span class="methodname"><a href="eventbuffer.unfreeze.html" class="methodname">unfreeze</a></span>
    ( <span class="methodparam">
    <span class="type">bool</span>
     <code class="parameter">$at_front</code>
   </span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">bool</span>
   <span class="methodname"><a href="eventbuffer.unlock.html" class="methodname">unlock</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="type">void</span>
   <span class="methodname"><a href="eventbuffer.write.html" class="methodname">write</a></span>
    ( <span class="methodparam">
    <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span>
     <code class="parameter">$fd</code>
   </span>
   [, <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$howmuch</code>
   </span>
  ] )</div>

   }</div>

  </div>

  <div class="section" id="eventbuffer.props">
   <h2 class="title">属性</h2>
   <dl>

    
     <dt id="eventbuffer.props.length">
      <var class="varname"><var class="varname">length</var></var>
     </dt>

     <dd>

      <p class="para">
       The number of bytes stored in an event buffer.
      </p>
     </dd>

    
    
     <dt id="eventbuffer.props.contiguous-space">
      <var class="varname"><var class="varname">contiguous_space</var></var>
     </dt>

     <dd>

      <p class="para">
       The number of bytes stored contiguously at the front of the buffer. The
       bytes in a buffer may be stored in multiple separate chunks of memory;
       the property returns the number of bytes currently stored in the first
       chunk.
      </p>
     </dd>

    
   </dl>

  </div>


  <div class="section" id="eventbuffer.constants">
   <h2 class="title">预定义常量</h2>
   <dl>

    
     <dt id="eventbuffer.constants.eol-any">
      <strong><code>EventBuffer::EOL_ANY</code></strong>
     </dt>

     <dd>

      <p class="para">
       The end of line is any sequence of any number of carriage return and
       linefeed characters. This format is not very useful; it exists mainly
       for backward compatibility.
      </p>
     </dd>

    
    
     <dt id="eventbuffer.constants.eol-crlf">
      <strong><code>EventBuffer::EOL_CRLF</code></strong>
     </dt>

     <dd>

      <p class="para">
       The end of the line is an optional carriage return, followed by a
       linefeed. (In other words, it is either a
       <em>&quot;\r\n&quot;</em>
       or a
       <em>&quot;\n&quot;</em>
       .) This format is useful in parsing text-based Internet protocols,
       since the standards generally prescribe a
       <em>&quot;\r\n&quot;</em>
       line-terminator, but nonconformant clients sometimes say just
       <em>&quot;\n&quot;</em>
       .
      </p>
     </dd>

    
    
     <dt id="eventbuffer.constants.eol-crlf-strict">
      <strong><code>EventBuffer::EOL_CRLF_STRICT</code></strong>
     </dt>

     <dd>

      <p class="para">
       The end of a line is a single carriage return, followed by a single
       linefeed. (This is also known as
       <em>&quot;\r\n&quot;</em>
       . The ASCII values are
       <strong><code>0x0D</code></strong>
       <strong><code>0x0A</code></strong>
       ).
      </p>
     </dd>

    
    
     <dt id="eventbuffer.constants.eol-lf">
      <strong><code>EventBuffer::EOL_LF</code></strong>
     </dt>

     <dd>

      <p class="para">
       The end of a line is a single linefeed character. (This is also known
       as
       <em>&quot;\n&quot;</em>
       . It is ASCII value is
       <strong><code>0x0A</code></strong>
       .)
      </p>
     </dd>

    
    
     <dt id="eventbuffer.constants.ptr-set">
      <strong><code>EventBuffer::PTR_SET</code></strong>
     </dt>

     <dd>

      <p class="para">
       Flag used as argument of
       <span class="methodname"><strong>EventBuffer::setPosition()</strong></span>
       method. If this flag specified, the position pointer is moved to an
       absolute position within the buffer.
      </p>
     </dd>

    
    
     <dt id="eventbuffer.constants.ptr-add">
      <strong><code>EventBuffer::PTR_ADD</code></strong>
     </dt>

     <dd>

      <p class="para">
       The same as
       <strong><code>EventBuffer::PTR_SET</code></strong>
       , except this flag causes
       <span class="methodname"><strong>EventBuffer::setPosition()</strong></span>
       method to move position forward up to the specified number of
       bytes(instead of setting absolute position).
      </p>
     </dd>

    
   </dl>

  </div>

 </div>

 















































































































<h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="eventbuffer.add.html">EventBuffer::add</a> — Append data to the end of an event buffer</li><li><a href="eventbuffer.addbuffer.html">EventBuffer::addBuffer</a> — Move all data from a buffer provided to the current instance of EventBuffer</li><li><a href="eventbuffer.appendfrom.html">EventBuffer::appendFrom</a> — Moves the specified number of bytes from a source buffer to the
  end of the current buffer</li><li><a href="eventbuffer.construct.html">EventBuffer::__construct</a> — Constructs EventBuffer object</li><li><a href="eventbuffer.copyout.html">EventBuffer::copyout</a> — Copies out specified number of bytes from the front of the buffer</li><li><a href="eventbuffer.drain.html">EventBuffer::drain</a> — Removes specified number of bytes from the front of the buffer
  without copying it anywhere</li><li><a href="eventbuffer.enablelocking.html">EventBuffer::enableLocking</a> — 说明</li><li><a href="eventbuffer.expand.html">EventBuffer::expand</a> — Reserves space in buffer</li><li><a href="eventbuffer.freeze.html">EventBuffer::freeze</a> — Prevent calls that modify an event buffer from succeeding</li><li><a href="eventbuffer.lock.html">EventBuffer::lock</a> — Acquires a lock on buffer</li><li><a href="eventbuffer.prepend.html">EventBuffer::prepend</a> — Prepend data to the front of the buffer</li><li><a href="eventbuffer.prependbuffer.html">EventBuffer::prependBuffer</a> — Moves all data from source buffer to the front of current buffer</li><li><a href="eventbuffer.pullup.html">EventBuffer::pullup</a> — Linearizes data within buffer
  and returns it's contents as a string</li><li><a href="eventbuffer.read.html">EventBuffer::read</a> — Read data from an evbuffer and drain the bytes read</li><li><a href="eventbuffer.readfrom.html">EventBuffer::readFrom</a> — Read data from a file onto the end of the buffer</li><li><a href="eventbuffer.readline.html">EventBuffer::readLine</a> — Extracts a line from the front of the buffer</li><li><a href="eventbuffer.search.html">EventBuffer::search</a> — Scans the buffer for an occurrence of a string</li><li><a href="eventbuffer.searcheol.html">EventBuffer::searchEol</a> — Scans the buffer for an occurrence of an end of line</li><li><a href="eventbuffer.substr.html">EventBuffer::substr</a> — Substracts a portion of the buffer data</li><li><a href="eventbuffer.unfreeze.html">EventBuffer::unfreeze</a> — Re-enable calls that modify an event buffer</li><li><a href="eventbuffer.unlock.html">EventBuffer::unlock</a> — Releases lock acquired by EventBuffer::lock</li><li><a href="eventbuffer.write.html">EventBuffer::write</a> — Write contents of the buffer to a file or socket</li></ul>
</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="eventbase.stop.html">EventBase::stop</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="eventbuffer.add.html">EventBuffer::add</a></div>
 <div class="up"><a href="book.event.html">Event</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
